package com.work.common.result;

import lombok.Data;

@Data
public class Result<T> {
    private Integer code;
    private String msg;
    private T data;

    public Result(int code, String msg, T data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }
    public Result(ResultType resultType, T data) {
        this(resultType.getCode(), resultType.getMsg(), data);
    }
    public Result(ResultType resultType) {
        this(resultType.getCode(), resultType.getMsg(), null);
    }

    public Result(int code, String msg) {
        this(code, msg, null);
    }

    public Result(int code, T data) {
        this(code, null, data);
    }

    public Result(int code) {
        this(code, null, null);
    }

    public Result() {
    }

    public static <T> Result<T> success(T data) {
        return new Result<>(200,"success", data);
    }

    public static <T> Result<T> success() {
        return new Result<>(200,"success", null);
    }

    public static <T> Result<T> success(ResultType resultType) {
        return new Result<>(resultType.getCode(), resultType.getMsg(), null);
    }

    public static <T> Result<T> success(ResultType resultType, T data){
        return new Result<>(resultType, data);
    }

    public static <T> Result<T> fail(ResultType resultType) {
        return new Result<>(resultType, null);
    }

    public static <T> Result<T> fail(ResultType resultType, T data) {
        return new Result<>(resultType, data);
    }
    public static <T> Result<T> fail() {
        return new Result<>(10001,"fail", null);
    }
    public static <T> Result<T> fail(String msg) {
        return new Result<>(10001, msg, null);
    }
    public static <T> Result<T> fail(String msg, T data) {
        return new Result<>(10001, msg, data);
    }
    public static <T> Result<T> fail(int code, String msg) {
        return new Result<>(code, msg, null);
    }
    public static <T> Result<T> fail(int code, String msg, T data) {
        return new Result<>(code, msg, data);
    }
}
